package fileIO;

import java.sql.*;

public class DataBase 
{
	Connection conn;
	Statement statement;
	String query;
	ResultSet results;
	public DataBase(String database)
	{
		try
		{
			//                                             Connection String       Username       Password
			Connection conn = DriverManager.getConnection("jdbc:h2:./databases/"+database, "guildmaster", "guildmaster");			
			statement = conn.createStatement();
			//TODO: Offload syntax into documentation
/*			This stuff shows how to structure stuff. Should be offloaded into docuemntation
 * //		query = "DROP TABLE Names";
			stmt.execute(query);
	//		query = "CREATE TABLE Names (ID INT PRIMARY KEY auto_increment, FName VARCHAR(255), LName VARCHAR(255), Gender INT)";
//			stmt.execute(query);
			query = "INSERT into Names (FName, LName, Gender) Values ('Robert', 'Frost', '1')";
			stmt.execute(query);
			query = "INSERT into Names (FName, LName, Gender) Values ('Xiao', 'Frost', '3')";
			stmt.execute(query);
			query = "INSERT into Names (FName, LName, Gender) Values ('Xiao', 'Frost', '2')";
			stmt.execute(query);
			*/
			/*
			query = "Select * From Names";
			ResultSet rs = stmt.executeQuery(query);
			System.out.println("___________DB Results__________");
			while(rs.next())
			{
				for(int i=1; i<=rs.getMetaData().getColumnCount(); i++)
					System.out.print(rs.getString(i) + ", ");
				System.out.println();
			}
			System.out.println("_______________________________");
			conn.close();
			
			*/
			conn.close();
		} catch (SQLException e)
		{
			System.err.println("Database initialization failed.");
			e.printStackTrace();
		}
		
	} //TODO:cleanup DB when exiting
}
